Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add callback support in settings and tools #590

Merged
merged 13 commits into from
Oct 16, 2024
Merged

Conversation

nadolskit
Copy link
Contributor

Adds callback support to Settings
Tools can invoke these callbacks

I wrote this in a way so that the callbacks are immutable, future flexibility, and direct.
There will likely be more tools using this infrastructure in the future.

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Oct 15, 2024
paperqa/settings.py Outdated Show resolved Hide resolved
@nadolskit nadolskit requested a review from jamesbraza October 15, 2024 19:59
paperqa/settings.py Outdated Show resolved Hide resolved
paperqa/settings.py Outdated Show resolved Hide resolved
paperqa/agents/tools.py Outdated Show resolved Hide resolved
paperqa/settings.py Outdated Show resolved Hide resolved
tests/test_agents.py Outdated Show resolved Hide resolved
Change callbacks to be lists of functions rather than just functions

Enhance tests
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Oct 15, 2024
paperqa/agents/tools.py Outdated Show resolved Hide resolved
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Oct 16, 2024
paperqa/agents/tools.py Outdated Show resolved Hide resolved
paperqa/agents/tools.py Outdated Show resolved Hide resolved
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Oct 16, 2024
paperqa/settings.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@mskarlin mskarlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice -- looks good to me, I'm wondering if this could create serialization issues for the Settings object, but that would be on the user as implemented here.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 16, 2024
@mskarlin mskarlin merged commit 6357cae into main Oct 16, 2024
5 checks passed
@mskarlin mskarlin deleted the settings-callbacks branch October 16, 2024 15:13
@pytest.mark.flaky(reruns=3, only_rerun=["AssertionError", "EmptyDocsError"])
@pytest.mark.asyncio
async def test_agent_sharing_state(
agent_test_settings: Settings, subtests: SubTests
agent_test_settings: Settings, subtests: SubTests, callback_type: str
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be callback_type: str | None

gather_evidence_initialized_callback = AsyncMock()
gather_evidence_completed_callback = AsyncMock()

callbacks = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it really matters, but it's more future proof to use callbacks.update here instead of redefining

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants